import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/* Layout */
import Layout from '@/layout'
// 导入动态路由的配置
import employeesRouter from '@/router/modules/employees'
import approvalsRouter from '@/router/modules/approvals'
import attendancesRouter from '@/router/modules/attendances'
import departmentsRouter from '@/router/modules/departments'
import permissionRouter from '@/router/modules/permission'
import salarysRouter from '@/router/modules/salarys'
import settingRouter from '@/router/modules/setting'
import socialRouter from '@/router/modules/social'
// 配置路由规则
// 1.动态路由=》需要做权限控制的路由，用户如果权限不一致访问到的路由也不一样
export const asyncRoutes = [
  departmentsRouter,
  settingRouter,
  employeesRouter,
  permissionRouter,
  approvalsRouter,
  attendancesRouter,
  salarysRouter,
  socialRouter

]
// 2.静态路由=》不需要做权限控制的路由，每个用户都可以正常访问
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 员工批量导入
  {
    path:'/import',
    component: Layout,
    children:[
      {
        path:'',
        component:()=>import('@/views/import')
      }
    ]

  },
  {
    path: '/',
    // 父页面
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  // 每次切换页面，对页面的滚动条滚动位置重置为0
  scrollBehavior: () => ({ y: 0 }),
  /** // 路由的配置数组
   * 回顾：合并对象=》（...obj1,...obj2）
   * 合并数组：[...ary1,...ary2]
   */
  // 合并静态和动态的路由地址
  routes: [...constantRoutes, ...asyncRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
